<?php
add_action('admin_menu','fengxl_admin_fstmenu');
function fengxl_admin_fstmenu()
{

    add_menu_page(__('主题设置'),__('主题设置'),9,'custom_themes_option','company_pagemanage');
    add_submenu_page('custom_themes_option','举报信息','举报信息',9,'c_reports','iglei_c_reports');

}
//页面管理功能
function company_pagemanage()
{
if($_POST['test_hidden'] == 'y')
   {
	   
       $options = array ('news_title', 'news_link','news_cn_id','news_id','tj_title','tj_link','zt_title','zt_link');
       foreach ( $options as $opt )
		{
            update_option('iglei_'.$opt, $_POST[$opt]);	
		}
?>
   <div id="message" class="updated">保存成功!</div>
<?php
   }

?>
<style>
#news_title,#tj_title,#cat_num{ width:150px;}
.form-table th { width:130px;}
</style>
  <div class="wrap">
  <h2>首页设置</h2>
  <form action="" method="post" id="submit_company_form">
  	<fieldset style="border:1px solid #ddd; padding-bottom:20px; margin-top:20px;">
	<legend style="margin-left:5px; padding:0 5px; color:#2481C6;text-transform:uppercase;"><strong>板块一</strong></legend>
		<table class="form-table">
        <tr>
			<th align="right"><label for="news_title"><strong>主标题：</strong></label></th>
			<td>
				<input name="news_title" type="text" id="news_title" value="<?php echo get_option('iglei_news_title'); ?>" class="regular-text" />
                &nbsp;&nbsp;<label for="news_link"><strong>链接地址：</strong></label>
                <input name="news_link" type="text" id="news_link" value="<?php echo get_option('iglei_news_link'); ?>" class="regular-text" />
			</td>
		</tr>
		<tr>
			<th><label for="news_cn_id"><strong>国内新闻文章ID：</strong></label></th>
			<td>
				<input name="news_cn_id" type="text" id="news_cn_id"  value="<?php echo get_option('iglei_news_cn_id'); ?>" class="regular-text" /><span>(&nbsp;用逗号隔开,比如:1,2,3&nbsp;)</span>
			</td>
		</tr>
		<tr>
			<th><label for="news_id"><strong>综合新闻文章ID：</strong></label></th>
			<td>
				<input name="news_id" type="text" id="news_id" value="<?php echo get_option('iglei_news_id'); ?>" class="regular-text" /><span>(&nbsp;用逗号隔开,比如:1,2,3&nbsp;)</span>
			</td>
		</tr>		
	</table>
	</fieldset>
    <fieldset style="border:1px solid #ddd; padding-bottom:20px; margin-top:20px;">
	<legend style="margin-left:5px; padding:0 5px; color:#2481C6;text-transform:uppercase;"><strong>板块二</strong></legend>
		<table class="form-table">
        <tr>
			<th align="right"><label for="tj_title"><strong>主标题：</strong></label></th>
			<td>
				<input name="tj_title" type="text" id="tj_title" value="<?php echo get_option('iglei_tj_title'); ?>" class="regular-text" />
                 &nbsp;&nbsp;<label for="tj_link"><strong>链接地址：</strong></label>
                 <input name="tj_link" type="text" id="tj_link" value="<?php echo get_option('iglei_tj_link'); ?>" class="regular-text" />
			</td>
		</tr>		
	</table>
	</fieldset>
    
    <fieldset style="border:1px solid #ddd; padding-bottom:20px; margin-top:20px;">
	<legend style="margin-left:5px; padding:0 5px; color:#2481C6;text-transform:uppercase;"><strong>专题板块</strong></legend>
		<table class="form-table">
        <tr>
			<th align="right"><label for="zt_title"><strong>主标题：</strong></label></th>
			<td>
				<input name="zt_title" type="text" id="zt_title" value="<?php echo get_option('iglei_zt_title'); ?>" class="regular-text" />
                 &nbsp;&nbsp;<label for="tj_link"><strong>链接地址：</strong></label>
                 <input name="zt_link" type="text" id="zt_link" value="<?php echo get_option('iglei_zt_link'); ?>" class="regular-text" />
			</td>
		</tr>		
	</table>	
    </fieldset>
  
<?php /*?>  <fieldset style="border:1px solid #ddd; padding-bottom:20px; margin-top:20px;">
	<legend style="margin-left:5px; padding:0 5px; color:#2481C6;text-transform:uppercase;"><strong>分类板块</strong></legend>
		<table class="form-table">
          <tr>
			<th align="right"><label for="cat_num"><strong>板块数量：</strong></label></th>
			<td>
				<input name="cat_num" type="text" id="cat_num" value="<?php echo get_option('iglei_cat_num'); ?>" class="regular-text" />
			</td>
		</tr>	
         <tr>
			<th align="right"><label for="tj_title"><strong>主标题：</strong></label></th>
			<td>
				<input name="tj_title" type="text" id="tj_title" value="<?php echo get_option('iglei_tj_title'); ?>" class="regular-text" />
                 &nbsp;&nbsp;<label for="tj_link"><strong>链接地址：</strong></label>
                 <input name="tj_link" type="text" id="tj_link" value="<?php echo get_option('iglei_tj_link'); ?>" class="regular-text" />
			</td>
		</tr>	
        <tr>
			<th align="right"><label for="show_company"><strong>预览页面：</strong></label></th>
			<td>
                <?php wp_dropdown_pages("name=show_company&show_option_none=".__('- 请选择 -')."&selected=" .get_option('lzpm_show_company')); ?>
			</td>
		</tr>
		<tr>
			<th><label for="pay_page"><strong>支付页面：</strong></label></th>
			<td>
                <?php wp_dropdown_pages("name=pay_page&show_option_none=".__('- 请选择 -')."&selected=" .get_option('lzpm_pay_page')); ?>
			</td>
		</tr>		
	</table>	
    </fieldset><?php */?>
  <p>
  <input style="cursor:pointer; width:100px; height:30px;" type="submit" name="submit" value="保存" />
  <input type="hidden" name="test_hidden" value="y"  />
  </p>
  </form>
  </div>
<?php } 
function iglei_c_reports(){
	
	global $table_prefix, $wpdb;
		
	$base_name = $_REQUEST['page'];
        
	$base_page = 'admin.php?page='.$base_name;
	$wp = get_bloginfo('wpurl');
	$table_name = $table_prefix."reports";
	$snshare_log_perpage=10;
	if(!empty($_POST['snshare_dellog']))
	{
		$snshare_sql="TRUNCATE $table_name;";
		mysql_query($snshare_sql);
	}
	$total_shares = $wpdb->get_var("SELECT COUNT(rid) FROM $table_name;");
	if(empty($_REQUEST['snshare_page']) || $_REQUEST['snshare_page']<1)
		$snshare_page=1;
	else
		$snshare_page=$_REQUEST['snshare_page'];

	$offset = ($snshare_page-1) * $snshare_log_perpage;

				
	if(empty($_REQUEST['snshare_sortpage']) || $_REQUEST['snshare_sortpage']<1)
		$snshare_sortpage=1;
	else
		$snshare_sortpage=$_REQUEST['snshare_sortpage'];

	$total_pages = ceil($total_shares / $snshare_log_perpage);

	$snshare_sql="SELECT * FROM  $table_name ORDER BY time DESC LIMIT $offset,$snshare_log_perpage;";
	$snshare_logs = $wpdb->get_results($snshare_sql);

?>
<div class="wrap">

	<h2>举报信息</h2><br />
        
	<table class="widefat">
		<thead>
			<tr>
			  <th>举报名称</th>
			  <th>举报地址</th>
			  <th>举报内容</th>
			  <th>举报时间</th>
			</tr>
		</thead>
		<tbody>
<?php
		if($snshare_logs) {
			$i = 0;
			foreach($snshare_logs as $snshare_log) {
				if($i%2 == 0) {
					$style = 'class="alternate"';
				}  else {
					$style = '';
				}

				$snshare_posttitle= $snshare_log->rname;
				$snshare_posturl= $snshare_log->posturl;
				$snshare_postimg= $snshare_log->rcontent;
				$snshare_time= $snshare_log->time;

				echo "<tr $style>\n";
				echo "<td><a href=\"".$snshare_posturl."\" target=\"_blank\">".$snshare_posttitle."</a></td>\n";
				echo "<td><a href=\"".$snshare_posturl."\" target=\"_blank\">".$snshare_posturl."</a></td>\n";
				echo "<td>".$snshare_postimg."</td>\n";
				echo "<td>".$snshare_time."</td>\n";
				echo "</tr>\n";
				$i++;
			}
			
		}
		else {
			echo '<tr><td colspan="5" align="center"><strong>'.__('没有相关记录', 'sinoshare').'</strong></td></tr>';
		}
?>
		</tbody>
	</table>
		<!-- <分页> -->
		<?php
			if($total_pages > 1) {
		?>
		<br />
		<table class="widefat">
			<tr>
				<td align="left" width="30%">
					<?php
						if($snshare_page > 1 && ((($snshare_page*$snshare_log_perpage)-($snshare_log_perpage-1)) <= $total_shares)) {
							echo '<strong>&laquo;</strong> <a href="'.$base_page.'&amp;snshare_page='.($snshare_page-1).'&amp;snshare_sortpage='.$snshare_sortpage.'" title="&laquo; '.__('前一页', 'sinoshare').'">'.__('前一页', 'sinoshare').'</a>';
						} else {
							echo '&nbsp;';
						}
					?>
				</td>
                <td colspan="2" align="center" width="30%">
					<?php printf(__('总页数 (%s): ', 'sinoshare'), $total_pages); ?>
					<?php
						if ($snshare_page >= 4) {
							echo '<strong><a href="'.$base_page.'&amp;snshare_page=1'.'&amp;snshare_sortpage='.$snshare_sortpage.'" title="'.__('第一页', 'sinoshare').'">&laquo; '.__('第一页', 'sinoshare').'</a></strong> ... ';
						}
						if($snshare_page > 1) {
							echo ' <strong><a href="'.$base_page.'&amp;snshare_page='.($snshare_page-1).'&amp;snshare_sortpage='.$snshare_sortpage.'" title="&laquo; '.__('第', 'sinoshare').($snshare_page-1).__('页', 'sinoshare').'">&laquo;</a></strong> ';
						}
						for($i = $snshare_page - 2 ; $i  <= $snshare_page +2; $i++) {
							if ($i >= 1 && $i <= $total_pages) {
								if($i == $snshare_page) {
									echo '<strong>['.$i.']</strong> ';
								} else {
									echo '<a href="'.$base_page.'&amp;snshare_page='.($i).'&amp;snshare_sortpage='.$snshare_sortpage.'" title="'.__('第', 'sinoshare').$i.__('页', 'sinoshare').'">'.$i.'</a> ';
								}
							}
						}
						if($snshare_page < $total_pages) {
							echo ' <strong><a href="'.$base_page.'&amp;snshare_page='.($snshare_page+1).'&amp;snshare_sortpage='.$snshare_sortpage.'" title="'.__('第', 'sinoshare').($snshare_page+1).__('页', 'sinoshare').' &raquo;">&raquo;</a></strong> ';
						}
						if (($snshare_page+2) < $total_pages) {
							echo ' ... <strong><a href="'.$base_page.'&amp;snshare_page='.($total_pages).'&amp;snshare_sortpage='.$snshare_sortpage.'" title="'.__('最后一页', 'sinoshare').'">'.__('最后一页', 'sinoshare').' &raquo;</a></strong>';
						}
					?>
				</td>
				<td align="right" width="30%">
					<?php
						if($snshare_page >= 1 && ((($snshare_page*$snshare_log_perpage)+1) <=  $total_shares)) {
							echo '<a href="'.$base_page.'&amp;snshare_page='.($snshare_page+1).'&amp;snshare_sortpage='.$snshare_sortpage.'" title="'.__('下一页', 'sinoshare').' &raquo;">'.__('下一页', 'sinoshare').'</a> <strong>&raquo;</strong>';
						} else {
							echo '&nbsp;';
						}
					?>
				</td>
			</tr>
		</table>
		<?php
			}
		?>
		<!-- </分页> --><br /><br />
		<div align="left">
		  <form name="snshare_buttonform" method="post" action="<?php echo $base_page?>">
		   <input type="submit" name="snshare_dellog" value="<?php print('清空全部记录'); ?>" class="button" onclick="javascript:snshare_buttonform.action='<?php echo $base_page?>';snshare_buttonform.target='';return confirm('真的要删除全部记录吗？');"/>
		   </form>
		</div>


</div>
<?php 
}

?>
